<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *玩家管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$uniacid=$_SESSION['uniacid'];
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$uniacid;
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	} 
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_yousetli_player',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=pdo_get('core_members',array('id'=>$item['mid'],'uniacid'=>$uniacid));
			$item['createtime']=date('y-m-d h:i:s',$item['createtime']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'玩家列表'),
		),
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'member.nickname','title'=>'玩家昵称','type'=>'string'),
			array('name'=>'member.avatar','title'=>'玩家头像','type'=>'image'),
			array('name'=>'money','title'=>'获得优惠总额','type'=>'string'),
		//	array('name'=>'status','title'=>'是否启用','type'=>'switch','set'=>'set'),
			array('name'=>'createtime','title'=>'参与时间','type'=>'string'),
		)),
		'search'=>array(
			array('name'=>'member.nickname','title'=>'玩家昵称','type'=>'string','width'=>'15'),
			//array('name'=>'status','title'=>'是否启用','type'=>'radio','options'=>'status'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_yousetli_player',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要编辑的玩家！','error');
	}
	$post=get_postdata();
	if(isset($post['status'])){
		pdo_update('jy_yousetli_player',array('status'=>intval($post['status'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}
